package com.pokermind.dse.tcp.client.preset;

import java.util.*;

/**
 * 预设场景配置 - 完整的牌局流程
 * 
 * @author PokerMind Team
 */
public class PresetScenario {
    
    private String scenarioName;
    private String tableId;
    private int bigBlind;
    private int smallBlind;
    private Map<String, PlayerConfig> players;
    private List<String> boardCards;
    private Map<String, List<ActionConfig>> streetActions;
    private String winnerId;  // 赢家玩家ID（用于摊牌结算）
    private RunItTwiceConfig runItTwice;  // Run It Twice 配置
    
    /**
     * 玩家配置
     */
    public static class PlayerConfig {
        private String playerId;
        private String position;
        private int initialStack;
        private List<String> holeCards;
        
        public PlayerConfig(String playerId, String position, int initialStack, List<String> holeCards) {
            this.playerId = playerId;
            this.position = position;
            this.initialStack = initialStack;
            this.holeCards = holeCards;
        }
        
        public String getPlayerId() { return playerId; }
        public String getPosition() { return position; }
        public int getInitialStack() { return initialStack; }
        public int getStack() { return initialStack; }  // 别名
        public List<String> getHoleCards() { return holeCards; }
    }
    
    /**
     * 行动配置
     */
    public static class ActionConfig {
        private String playerId;
        private String action;
        private int amount;
        
        public ActionConfig(String playerId, String action, int amount) {
            this.playerId = playerId;
            this.action = action;
            this.amount = amount;
        }
        
        public String getPlayerId() { return playerId; }
        public String getAction() { return action; }
        public int getAmount() { return amount; }
    }
    
    /**
     * Run It Twice 配置
     */
    public static class RunItTwiceConfig {
        private boolean enabled;
        private List<RunResult> runs;
        
        public RunItTwiceConfig(boolean enabled, List<RunResult> runs) {
            this.enabled = enabled;
            this.runs = runs;
        }
        
        public boolean isEnabled() { return enabled; }
        public List<RunResult> getRuns() { return runs; }
    }
    
    /**
     * Run 结果
     */
    public static class RunResult {
        private int run;
        private List<String> board;
        private int potShare;
        private List<String> winners;
        private List<PlayerRunDetail> details;
        
        public RunResult(int run, List<String> board, int potShare, List<String> winners, List<PlayerRunDetail> details) {
            this.run = run;
            this.board = board;
            this.potShare = potShare;
            this.winners = winners;
            this.details = details;
        }
        
        public int getRun() { return run; }
        public List<String> getBoard() { return board; }
        public int getPotShare() { return potShare; }
        public List<String> getWinners() { return winners; }
        public List<PlayerRunDetail> getDetails() { return details; }
    }
    
    /**
     * 玩家运行详情
     */
    public static class PlayerRunDetail {
        private String playerId;
        private String handRank;
        private String handDesc;
        private int result;
        
        public PlayerRunDetail(String playerId, String handRank, String handDesc, int result) {
            this.playerId = playerId;
            this.handRank = handRank;
            this.handDesc = handDesc;
            this.result = result;
        }
        
        public String getPlayerId() { return playerId; }
        public String getHandRank() { return handRank; }
        public String getHandDesc() { return handDesc; }
        public int getResult() { return result; }
    }
    
    public PresetScenario(String scenarioName, String tableId, int bigBlind, int smallBlind) {
        this.scenarioName = scenarioName;
        this.tableId = tableId;
        this.bigBlind = bigBlind;
        this.smallBlind = smallBlind;
        this.players = new LinkedHashMap<>();
        this.streetActions = new LinkedHashMap<>();
        this.boardCards = new ArrayList<>();
    }
    
    public void addPlayer(PlayerConfig player) {
        players.put(player.getPlayerId(), player);
    }
    
    public void setBoardCards(List<String> cards) {
        this.boardCards = cards;
    }
    
    public void addStreetAction(String street, ActionConfig action) {
        streetActions.computeIfAbsent(street, k -> new ArrayList<>()).add(action);
    }
    
    public String getScenarioName() { return scenarioName; }
    public String getTableId() { return tableId; }
    public String getWinnerId() { return winnerId; }
    public void setWinnerId(String winnerId) { this.winnerId = winnerId; }
    public RunItTwiceConfig getRunItTwice() { return runItTwice; }
    public void setRunItTwice(RunItTwiceConfig runItTwice) { this.runItTwice = runItTwice; }
    public int getBigBlind() { return bigBlind; }
    public int getSmallBlind() { return smallBlind; }
    public Map<String, PlayerConfig> getPlayers() { return players; }
    public List<String> getBoardCards() { return boardCards; }
    public Map<String, List<ActionConfig>> getStreetActions() { return streetActions; }
    
    /**
     * 创建经典BTN vs BB场景（极简版）
     * 
     * 场景说明：
     * - BTN持有As Ks（强牌）
     * - BB持有7h 2d（弱牌）
     * - BTN加注，BB弃牌（翻前结束）
     * 
     * 总操作数：2个（raise + fold）
     */
    public static PresetScenario createClassicBTNvsBB() {
        PresetScenario scenario = new PresetScenario(
            "经典BTN vs BB对决（2人对决）",
            "PRESET_TABLE_001",
            200,
            100
        );
        
        // 玩家配置 - 2人对决（Heads-Up）
        // 2人桌: 位置1=BTN(兼任SB), 位置2=BB
        scenario.addPlayer(new PlayerConfig("player_sb", "BTN", 10000, Arrays.asList("As", "Ks")));
        scenario.addPlayer(new PlayerConfig("player_bb", "BB", 10000, Arrays.asList("7h", "2d")));
        
        // 公共牌（翻前结束，无需公共牌）
        scenario.setBoardCards(Arrays.asList());
        
        // 翻前行动 - 极简流程
        scenario.addStreetAction("preflop", new ActionConfig("player_sb", "raise", 400));  // BTN加注到500
        scenario.addStreetAction("preflop", new ActionConfig("player_bb", "fold", 0));     // BB弃牌
        
        // 赢家：player_sb（对手弃牌）
        scenario.setWinnerId("player_sb");
        
        return scenario;
    }
    
    /**
     * 创建翻前3-bet测试场景
     */
    public static PresetScenario createPreflopThreeBet() {
        PresetScenario scenario = new PresetScenario(
            "翻前3-bet测试",
            "PRESET_TABLE_002",
            200,
            100
        );
        
        // 玩家配置
        scenario.addPlayer(new PlayerConfig("player_sb", "SB", 10000, Arrays.asList("2c", "7d")));
        scenario.addPlayer(new PlayerConfig("player_bb", "BB", 10000, Arrays.asList("Kh", "Kd")));
        scenario.addPlayer(new PlayerConfig("player_utg", "UTG", 10000, Arrays.asList("9s", "8s")));
        scenario.addPlayer(new PlayerConfig("player_mp", "MP", 10000, Arrays.asList("As", "Ks")));
        scenario.addPlayer(new PlayerConfig("player_co", "CO", 10000, Arrays.asList("Qd", "Jd")));
        scenario.addPlayer(new PlayerConfig("player_btn", "BTN", 10000, Arrays.asList("7c", "6c")));
        
        // 公共牌
        scenario.setBoardCards(Arrays.asList("Ac", "Kc", "3h", "5d", "2s"));
        
        // 翻前行动（测试3-bet）
        scenario.addStreetAction("preflop", new ActionConfig("player_utg", "fold", 0));
        scenario.addStreetAction("preflop", new ActionConfig("player_mp", "raise", 500));
        scenario.addStreetAction("preflop", new ActionConfig("player_co", "fold", 0));
        scenario.addStreetAction("preflop", new ActionConfig("player_btn", "fold", 0));
        scenario.addStreetAction("preflop", new ActionConfig("player_sb", "fold", 0));
        scenario.addStreetAction("preflop", new ActionConfig("player_bb", "raise", 1600));
        scenario.addStreetAction("preflop", new ActionConfig("player_mp", "call", 1100));
        
        // 翻牌圈行动（Ac Kc 3h）
        scenario.addStreetAction("flop", new ActionConfig("player_bb", "raise", 2000));
        scenario.addStreetAction("flop", new ActionConfig("player_mp", "call", 2000));
        
        // 转牌圈行动（5d）
        scenario.addStreetAction("turn", new ActionConfig("player_bb", "raise", 4000));
        scenario.addStreetAction("turn", new ActionConfig("player_mp", "fold", 0));
        
        // 赢家：player_bb（对手弃牌）
        scenario.setWinnerId("player_bb");
        
        return scenario;
    }
    
    /**
     * 创建全下场景
     */
    public static PresetScenario createAllInScenario() {
        PresetScenario scenario = new PresetScenario(
            "全下场景测试",
            "PRESET_TABLE_003",
            200,
            100
        );
        
        // 3人配置：按标准德州规则 BTN, SB, BB
        scenario.addPlayer(new PlayerConfig("player_btn", "BTN", 2000, Arrays.asList("Qd", "Qc")));
        scenario.addPlayer(new PlayerConfig("player_sb", "SB", 2000, Arrays.asList("2c", "7d")));
        scenario.addPlayer(new PlayerConfig("player_bb", "BB", 2000, Arrays.asList("Ah", "Kh")));
        
        // 公共牌
        scenario.setBoardCards(Arrays.asList("Qs", "Jh", "3c", "5d", "2s"));
        
        // 翻前行动（全下）：BTN先行动
        scenario.addStreetAction("preflop", new ActionConfig("player_btn", "raise", 500));
        scenario.addStreetAction("preflop", new ActionConfig("player_sb", "fold", 0));
        scenario.addStreetAction("preflop", new ActionConfig("player_bb", "raise", 1800));
        scenario.addStreetAction("preflop", new ActionConfig("player_btn", "raise", 1500));
        
        // 翻牌圈无行动（全下了）
        // 转牌圈无行动
        // 河牌圈无行动
        
        // 赢家：player_btn（QQQ三条 > AK高牌）
        scenario.setWinnerId("player_btn");
        
        return scenario;
    }
    
    /**
     * 创建3人底池场景
     */
    public static PresetScenario createMultiway3Players() {
        PresetScenario scenario = new PresetScenario(
            "3人底池场景",
            "PRESET_TABLE_004",
            200,
            100
        );
        
        // 3人配置：按标准德州规则 BTN, SB, BB
        scenario.addPlayer(new PlayerConfig("player_btn", "BTN", 5000, Arrays.asList("Ad", "As")));
        scenario.addPlayer(new PlayerConfig("player_sb", "SB", 5000, Arrays.asList("9h", "8h")));
        scenario.addPlayer(new PlayerConfig("player_bb", "BB", 5000, Arrays.asList("Kd", "Qd")));
        
        scenario.setBoardCards(Arrays.asList("Ah", "9c", "3d", "5s", "2h"));
        
        // 翻前行动：BTN先行动（翻前BTN在SB后行动）
        scenario.addStreetAction("preflop", new ActionConfig("player_btn", "raise", 400));
        scenario.addStreetAction("preflop", new ActionConfig("player_sb", "call", 300));
        scenario.addStreetAction("preflop", new ActionConfig("player_bb", "fold", 0));
        
        // 翻牌圈：SB先行动
        scenario.addStreetAction("flop", new ActionConfig("player_sb", "check", 0));
        scenario.addStreetAction("flop", new ActionConfig("player_btn", "bet", 600));
        scenario.addStreetAction("flop", new ActionConfig("player_sb", "call", 600));
        
        // 转牌圈
        scenario.addStreetAction("turn", new ActionConfig("player_sb", "check", 0));
        scenario.addStreetAction("turn", new ActionConfig("player_btn", "bet", 1000));
        scenario.addStreetAction("turn", new ActionConfig("player_sb", "fold", 0));
        
        scenario.setWinnerId("player_btn");
        return scenario;
    }
    
    /**
     * 创建4人多路底池场景
     */
    public static PresetScenario createMultiway4Players() {
        PresetScenario scenario = new PresetScenario(
            "4人多路底池",
            "PRESET_TABLE_005",
            200,
            100
        );
        
        // 4人配置：按标准德州规则 BTN, SB, BB, CO
        scenario.addPlayer(new PlayerConfig("player_btn", "BTN", 6000, Arrays.asList("9s", "9d")));
        scenario.addPlayer(new PlayerConfig("player_sb", "SB", 6000, Arrays.asList("Jc", "Tc")));
        scenario.addPlayer(new PlayerConfig("player_bb", "BB", 6000, Arrays.asList("Ks", "Js")));
        scenario.addPlayer(new PlayerConfig("player_co", "CO", 6000, Arrays.asList("8h", "7h")));
        
        scenario.setBoardCards(Arrays.asList("9h", "9c", "2d", "4s", "6h"));
        
        // 翻前行动：CO先行动（翻前从CO开始，然后BTN, SB, BB）
        scenario.addStreetAction("preflop", new ActionConfig("player_co", "raise", 500));
        scenario.addStreetAction("preflop", new ActionConfig("player_btn", "call", 500));
        scenario.addStreetAction("preflop", new ActionConfig("player_sb", "fold", 0));
        scenario.addStreetAction("preflop", new ActionConfig("player_bb", "call", 300));
        
        // 翻牌圈：BB先行动
        scenario.addStreetAction("flop", new ActionConfig("player_bb", "check", 0));
        scenario.addStreetAction("flop", new ActionConfig("player_co", "bet", 800));
        scenario.addStreetAction("flop", new ActionConfig("player_btn", "call", 800));
        scenario.addStreetAction("flop", new ActionConfig("player_bb", "fold", 0));
        
        scenario.addStreetAction("turn", new ActionConfig("player_co", "bet", 1200));
        scenario.addStreetAction("turn", new ActionConfig("player_btn", "call", 1200));
        
        scenario.addStreetAction("river", new ActionConfig("player_co", "check", 0));
        scenario.addStreetAction("river", new ActionConfig("player_btn", "check", 0));
        
        scenario.setWinnerId("player_btn");
        return scenario;
    }
    
    /**
     * 创建激进加注场景
     */
    public static PresetScenario createAggressiveRaising() {
        PresetScenario scenario = new PresetScenario(
            "激进加注场景",
            "PRESET_TABLE_006",
            200,
            100
        );
        
        // 2人配置：BTN, BB
        scenario.addPlayer(new PlayerConfig("player_btn", "BTN", 8000, Arrays.asList("Ac", "Kc")));
        scenario.addPlayer(new PlayerConfig("player_bb", "BB", 8000, Arrays.asList("5h", "4h")));
        
        scenario.setBoardCards(Arrays.asList("Ad", "Kh", "7c", "2d", "9s"));
        
        scenario.addStreetAction("preflop", new ActionConfig("player_btn", "raise", 400));
        scenario.addStreetAction("preflop", new ActionConfig("player_bb", "raise", 1200));
        scenario.addStreetAction("preflop", new ActionConfig("player_btn", "raise", 2000));
        scenario.addStreetAction("preflop", new ActionConfig("player_bb", "call", 800));
        
        scenario.addStreetAction("flop", new ActionConfig("player_bb", "check", 0));
        scenario.addStreetAction("flop", new ActionConfig("player_btn", "bet", 2000));
        scenario.addStreetAction("flop", new ActionConfig("player_bb", "fold", 0));
        
        scenario.setWinnerId("player_btn");
        return scenario;
    }
    
    /**
     * 创建保守场景（跟注为主）
     */
    public static PresetScenario createConservativePlay() {
        PresetScenario scenario = new PresetScenario(
            "保守跟注场景",
            "PRESET_TABLE_007",
            200,
            100
        );
        
        // 2人配置：BTN, BB
        scenario.addPlayer(new PlayerConfig("player_btn", "BTN", 4000, Arrays.asList("6d", "5d")));
        scenario.addPlayer(new PlayerConfig("player_bb", "BB", 4000, Arrays.asList("Th", "9h")));
        
        scenario.setBoardCards(Arrays.asList("6h", "6c", "5c", "3s", "2h"));
        
        scenario.addStreetAction("preflop", new ActionConfig("player_btn", "call", 100));
        scenario.addStreetAction("preflop", new ActionConfig("player_bb", "check", 0));
        
        scenario.addStreetAction("flop", new ActionConfig("player_bb", "check", 0));
        scenario.addStreetAction("flop", new ActionConfig("player_btn", "check", 0));
        
        scenario.addStreetAction("turn", new ActionConfig("player_bb", "bet", 200));
        scenario.addStreetAction("turn", new ActionConfig("player_btn", "call", 200));
        
        scenario.addStreetAction("river", new ActionConfig("player_bb", "check", 0));
        scenario.addStreetAction("river", new ActionConfig("player_btn", "check", 0));
        
        scenario.setWinnerId("player_btn");
        return scenario;
    }
    
    /**
     * 创建5人桌场景
     */
    public static PresetScenario create5MaxScenario() {
        PresetScenario scenario = new PresetScenario(
            "5人桌场景",
            "PRESET_TABLE_008",
            200,
            100
        );
        
        scenario.addPlayer(new PlayerConfig("player_sb", "SB", 7000, Arrays.asList("Qd", "Qh")));
        scenario.addPlayer(new PlayerConfig("player_bb", "BB", 7000, Arrays.asList("As", "Kd")));
        scenario.addPlayer(new PlayerConfig("player_utg", "UTG", 7000, Arrays.asList("9h", "8h")));
        scenario.addPlayer(new PlayerConfig("player_co", "CO", 7000, Arrays.asList("Jd", "Jc")));
        scenario.addPlayer(new PlayerConfig("player_btn", "BTN", 7000, Arrays.asList("3c", "2c")));
        
        scenario.setBoardCards(Arrays.asList("Qc", "Js", "9d", "4h", "8c"));
        
        scenario.addStreetAction("preflop", new ActionConfig("player_utg", "raise", 500));
        scenario.addStreetAction("preflop", new ActionConfig("player_co", "call", 500));
        scenario.addStreetAction("preflop", new ActionConfig("player_btn", "fold", 0));
        scenario.addStreetAction("preflop", new ActionConfig("player_sb", "call", 400));
        scenario.addStreetAction("preflop", new ActionConfig("player_bb", "call", 300));
        
        scenario.addStreetAction("flop", new ActionConfig("player_bb", "bet", 1000));
        scenario.addStreetAction("flop", new ActionConfig("player_utg", "call", 1000));
        scenario.addStreetAction("flop", new ActionConfig("player_co", "call", 1000));
        scenario.addStreetAction("flop", new ActionConfig("player_sb", "fold", 0));
        
        scenario.addStreetAction("turn", new ActionConfig("player_bb", "check", 0));
        scenario.addStreetAction("turn", new ActionConfig("player_utg", "bet", 1500));
        scenario.addStreetAction("turn", new ActionConfig("player_co", "fold", 0));
        
        scenario.setWinnerId("player_utg");
        return scenario;
    }
    
    /**
     * 创建6人桌场景
     */
    public static PresetScenario create6MaxScenario() {
        PresetScenario scenario = new PresetScenario(
            "6人桌场景",
            "PRESET_TABLE_009",
            200,
            100
        );
        
        // 按标准座位顺序添加：BTN, SB, BB, UTG, HJ, CO
        scenario.addPlayer(new PlayerConfig("player_btn", "BTN", 6000, Arrays.asList("2h", "2d")));
        scenario.addPlayer(new PlayerConfig("player_sb", "SB", 6000, Arrays.asList("Ks", "Qs")));
        scenario.addPlayer(new PlayerConfig("player_bb", "BB", 6000, Arrays.asList("7d", "7c")));
        scenario.addPlayer(new PlayerConfig("player_utg", "UTG", 6000, Arrays.asList("Ad", "Ah")));
        scenario.addPlayer(new PlayerConfig("player_hj", "HJ", 6000, Arrays.asList("4h", "4d")));
        scenario.addPlayer(new PlayerConfig("player_co", "CO", 6000, Arrays.asList("Kh", "Kc")));
        
        scenario.setBoardCards(Arrays.asList("Ac", "As", "7h", "9c", "3d"));
        
        scenario.addStreetAction("preflop", new ActionConfig("player_utg", "raise", 600));
        scenario.addStreetAction("preflop", new ActionConfig("player_hj", "fold", 0));
        scenario.addStreetAction("preflop", new ActionConfig("player_co", "call", 600));
        scenario.addStreetAction("preflop", new ActionConfig("player_btn", "fold", 0));
        scenario.addStreetAction("preflop", new ActionConfig("player_sb", "call", 500));
        scenario.addStreetAction("preflop", new ActionConfig("player_bb", "call", 400));
        
        scenario.addStreetAction("flop", new ActionConfig("player_bb", "check", 0));
        scenario.addStreetAction("flop", new ActionConfig("player_utg", "bet", 1200));
        scenario.addStreetAction("flop", new ActionConfig("player_co", "fold", 0));
        scenario.addStreetAction("flop", new ActionConfig("player_sb", "fold", 0));
        
        scenario.setWinnerId("player_utg");
        return scenario;
    }
    
    /**
     * 创建7人桌场景
     */
    public static PresetScenario create7MaxScenario() {
        PresetScenario scenario = new PresetScenario(
            "7人桌场景",
            "PRESET_TABLE_010",
            200,
            100
        );
        
        // 按标准座位顺序添加：BTN, SB, BB, UTG, LJ, HJ, CO
        scenario.addPlayer(new PlayerConfig("player_btn", "BTN", 5500, Arrays.asList("3h", "3d")));
        scenario.addPlayer(new PlayerConfig("player_sb", "SB", 5500, Arrays.asList("9c", "9h")));
        scenario.addPlayer(new PlayerConfig("player_bb", "BB", 5500, Arrays.asList("Ts", "Th")));
        scenario.addPlayer(new PlayerConfig("player_utg", "UTG", 5500, Arrays.asList("2d", "2c")));
        scenario.addPlayer(new PlayerConfig("player_lj", "LJ", 5500, Arrays.asList("6d", "6h")));
        scenario.addPlayer(new PlayerConfig("player_hj", "HJ", 5500, Arrays.asList("5d", "5h")));
        scenario.addPlayer(new PlayerConfig("player_co", "CO", 5500, Arrays.asList("Jd", "Jh")));
        
        scenario.setBoardCards(Arrays.asList("Ad", "As", "7d", "Ks", "Qc"));
        
        scenario.addStreetAction("preflop", new ActionConfig("player_utg", "raise", 400));
        scenario.addStreetAction("preflop", new ActionConfig("player_lj", "fold", 0));
        scenario.addStreetAction("preflop", new ActionConfig("player_hj", "fold", 0));
        scenario.addStreetAction("preflop", new ActionConfig("player_co", "call", 400));
        scenario.addStreetAction("preflop", new ActionConfig("player_btn", "fold", 0));
        scenario.addStreetAction("preflop", new ActionConfig("player_sb", "fold", 0));
        scenario.addStreetAction("preflop", new ActionConfig("player_bb", "call", 200));
        
        scenario.addStreetAction("flop", new ActionConfig("player_bb", "check", 0));
        scenario.addStreetAction("flop", new ActionConfig("player_utg", "bet", 800));
        scenario.addStreetAction("flop", new ActionConfig("player_co", "fold", 0));
        
        scenario.setWinnerId("player_utg");
        return scenario;
    }
    
    /**
     * 创建8人桌场景
     */
    public static PresetScenario create8MaxScenario() {
        PresetScenario scenario = new PresetScenario(
            "8人桌场景",
            "PRESET_TABLE_011",
            200,
            100
        );
        
        // 按标准座位顺序添加：BTN, SB, BB, UTG, UTG+1, LJ, HJ, CO
        scenario.addPlayer(new PlayerConfig("player_btn", "BTN", 5000, Arrays.asList("2s", "2h")));
        scenario.addPlayer(new PlayerConfig("player_sb", "SB", 5000, Arrays.asList("8c", "8h")));
        scenario.addPlayer(new PlayerConfig("player_bb", "BB", 5000, Arrays.asList("9d", "9c")));
        scenario.addPlayer(new PlayerConfig("player_utg", "UTG", 5000, Arrays.asList("Ac", "Ad")));
        scenario.addPlayer(new PlayerConfig("player_utg1", "UTG+1", 5000, Arrays.asList("3d", "3c")));
        scenario.addPlayer(new PlayerConfig("player_lj", "LJ", 5000, Arrays.asList("5h", "5c")));
        scenario.addPlayer(new PlayerConfig("player_hj", "HJ", 5000, Arrays.asList("7h", "7c")));
        scenario.addPlayer(new PlayerConfig("player_co", "CO", 5000, Arrays.asList("Js", "Jh")));
        
        scenario.setBoardCards(Arrays.asList("Ah", "Kh", "Qh", "Jd", "Tc"));
        
        scenario.addStreetAction("preflop", new ActionConfig("player_utg", "raise", 300));
        scenario.addStreetAction("preflop", new ActionConfig("player_utg1", "fold", 0));
        scenario.addStreetAction("preflop", new ActionConfig("player_lj", "fold", 0));
        scenario.addStreetAction("preflop", new ActionConfig("player_hj", "fold", 0));
        scenario.addStreetAction("preflop", new ActionConfig("player_co", "call", 300));
        scenario.addStreetAction("preflop", new ActionConfig("player_btn", "fold", 0));
        scenario.addStreetAction("preflop", new ActionConfig("player_sb", "fold", 0));
        scenario.addStreetAction("preflop", new ActionConfig("player_bb", "call", 100));
        
        scenario.addStreetAction("flop", new ActionConfig("player_bb", "check", 0));
        scenario.addStreetAction("flop", new ActionConfig("player_utg", "bet", 600));
        scenario.addStreetAction("flop", new ActionConfig("player_co", "fold", 0));
        
        scenario.setWinnerId("player_utg");
        return scenario;
    }
    
    /**
     * 创建9人满桌场景
     */
    public static PresetScenario createFullRing9Players() {
        PresetScenario scenario = new PresetScenario(
            "9人满桌场景",
            "PRESET_TABLE_012",
            200,
            100
        );
        
        // 按标准座位顺序添加：BTN, SB, BB, UTG, UTG+1, UTG+2, LJ, HJ, CO
        scenario.addPlayer(new PlayerConfig("player_btn", "BTN", 4500, Arrays.asList("2c", "2d")));
        scenario.addPlayer(new PlayerConfig("player_sb", "SB", 4500, Arrays.asList("Kd", "Kh")));
        scenario.addPlayer(new PlayerConfig("player_bb", "BB", 4500, Arrays.asList("9h", "9s")));
        scenario.addPlayer(new PlayerConfig("player_utg", "UTG", 4500, Arrays.asList("Ac", "As")));
        scenario.addPlayer(new PlayerConfig("player_utg1", "UTG+1", 4500, Arrays.asList("4d", "4c")));
        scenario.addPlayer(new PlayerConfig("player_utg2", "UTG+2", 4500, Arrays.asList("Qd", "Qh")));
        scenario.addPlayer(new PlayerConfig("player_lj", "LJ", 4500, Arrays.asList("6d", "6h")));
        scenario.addPlayer(new PlayerConfig("player_hj", "HJ", 4500, Arrays.asList("8h", "8c")));
        scenario.addPlayer(new PlayerConfig("player_co", "CO", 4500, Arrays.asList("Jd", "Jc")));
        
        scenario.setBoardCards(Arrays.asList("Ah", "Kc", "9c", "5d", "3h"));
        
        scenario.addStreetAction("preflop", new ActionConfig("player_utg", "raise", 400));
        scenario.addStreetAction("preflop", new ActionConfig("player_utg1", "fold", 0));
        scenario.addStreetAction("preflop", new ActionConfig("player_utg2", "fold", 0));
        scenario.addStreetAction("preflop", new ActionConfig("player_lj", "fold", 0));
        scenario.addStreetAction("preflop", new ActionConfig("player_hj", "fold", 0));
        scenario.addStreetAction("preflop", new ActionConfig("player_co", "call", 400));
        scenario.addStreetAction("preflop", new ActionConfig("player_btn", "fold", 0));
        scenario.addStreetAction("preflop", new ActionConfig("player_sb", "fold", 0));
        scenario.addStreetAction("preflop", new ActionConfig("player_bb", "call", 200));
        
        scenario.addStreetAction("flop", new ActionConfig("player_bb", "check", 0));
        scenario.addStreetAction("flop", new ActionConfig("player_utg", "bet", 800));
        scenario.addStreetAction("flop", new ActionConfig("player_co", "fold", 0));
        
        scenario.setWinnerId("player_utg");
        return scenario;
    }
    
    /**
     * 创建 Run It Twice 场景 - V4.6 新增
     * 2人对决，翻牌圈 All-In，执行 Run It Twice
     */
    public static PresetScenario createRunItTwice() {
        PresetScenario scenario = new PresetScenario(
            "Run It Twice 场景（2人All-In）",
            "PRESET_TABLE_RIT_001",
            200,
            100
        );
        
        // 2人对决：BTN vs BB
        scenario.addPlayer(new PlayerConfig("player_btn", "BTN", 10000, Arrays.asList("As", "Kh")));
        scenario.addPlayer(new PlayerConfig("player_bb", "BB", 10000, Arrays.asList("Qd", "Jd")));
        
        // 公共牌（翻牌圈）
        scenario.setBoardCards(Arrays.asList("2d", "9d", "5h", "4c", "7h"));
        
        // 翻前行动
        scenario.addStreetAction("preflop", new ActionConfig("player_btn", "raise", 400));
        scenario.addStreetAction("preflop", new ActionConfig("player_bb", "call", 200));
        
        // 翻牌圈 All-In
        scenario.addStreetAction("flop", new ActionConfig("player_bb", "bet", 1000));
        scenario.addStreetAction("flop", new ActionConfig("player_btn", "raise", 9400));  // All-In
        scenario.addStreetAction("flop", new ActionConfig("player_bb", "raise", 8400));  // Call All-In
        
        // Run It Twice 配置
        // 底池计算: 100(SB) + 200(BB) + 400 + 200 + 1000 + 9400 + 8400 = 19700
        // 每次分配: 19700 / 2 = 9850
        List<RunResult> runs = new ArrayList<>();
        int totalPot = 19700;
        int potSharePerRun = totalPot / 2;  // 9850
        
        // Run 1: player_btn 赢得一半底池
        List<PlayerRunDetail> run1Details = Arrays.asList(
            new PlayerRunDetail("player_btn", "pair", "Pair of Aces", potSharePerRun),
            new PlayerRunDetail("player_bb", "high_card", "Queen High", 0)
        );
        runs.add(new RunResult(1, Arrays.asList("2d", "9d", "5h", "4c", "7h"), potSharePerRun, 
                               Arrays.asList("player_btn"), run1Details));
        
        // Run 2: player_bb 赢得另一半底池
        List<PlayerRunDetail> run2Details = Arrays.asList(
            new PlayerRunDetail("player_btn", "pair", "Pair of Aces", 0),
            new PlayerRunDetail("player_bb", "flush", "Diamond Flush", potSharePerRun)
        );
        runs.add(new RunResult(2, Arrays.asList("2d", "9d", "5h", "8d", "3d"), potSharePerRun, 
                               Arrays.asList("player_bb"), run2Details));
        
        scenario.setRunItTwice(new RunItTwiceConfig(true, runs));
        
        // 最终赢家：平分（各赢一次）
        scenario.setWinnerId("player_btn");  // 用于计算最终净值，但 Run It Twice 场景会特殊处理
        
        return scenario;
    }
    
    /**
     * 创建 Run It Twice 6人场景
     * 场景：6人牌局，翻前4人弃牌，翻牌圈2人All-In触发RIT
     */
    public static PresetScenario createRunItTwice6Players() {
        PresetScenario scenario = new PresetScenario(
            "Run It Twice 6人场景（翻前4人弃牌，2人All-In）",
            "PRESET_TABLE_RIT_6P_001",
            200,
            100
        );
        
        // 6个玩家
        scenario.addPlayer(new PlayerConfig("player_alice", "BTN", 10000, 
            Arrays.asList("As", "Ks")));
        scenario.addPlayer(new PlayerConfig("player_bob", "SB", 8000, 
            Arrays.asList("Qh", "Jh")));
        scenario.addPlayer(new PlayerConfig("player_charlie", "BB", 12000, 
            Arrays.asList("7d", "7c")));
        scenario.addPlayer(new PlayerConfig("player_david", "UTG", 9000, 
            Arrays.asList("Ad", "Qd")));
        scenario.addPlayer(new PlayerConfig("player_emma", "HJ", 15000, 
            Arrays.asList("Kc", "Kh")));
        scenario.addPlayer(new PlayerConfig("player_frank", "CO", 7000, 
            Arrays.asList("9s", "8s")));
        
        scenario.setBoardCards(Arrays.asList("9d", "5d", "2h", "3c", "7s"));  // Run 1的最终公共牌
        
        // 翻前行动：David加注，Emma跟注，其他4人全弃
        scenario.addStreetAction("preflop", new ActionConfig("player_david", "raise", 600));
        scenario.addStreetAction("preflop", new ActionConfig("player_emma", "call", 600));
        scenario.addStreetAction("preflop", new ActionConfig("player_frank", "fold", 0));
        scenario.addStreetAction("preflop", new ActionConfig("player_alice", "fold", 0));
        scenario.addStreetAction("preflop", new ActionConfig("player_bob", "fold", 0));
        scenario.addStreetAction("preflop", new ActionConfig("player_charlie", "fold", 0));
        
        // 翻牌圈 All-In
        scenario.addStreetAction("flop", new ActionConfig("player_david", "bet", 2000));
        scenario.addStreetAction("flop", new ActionConfig("player_emma", "raise", 6000));
        scenario.addStreetAction("flop", new ActionConfig("player_david", "raise", 6400));  // All-In (David总投入9000)
        scenario.addStreetAction("flop", new ActionConfig("player_emma", "call", 400));     // Call All-In (Emma总投入7000)
        
        // Run It Twice 配置
        // 底池计算: 100(SB) + 200(BB) + 600(David) + 600(Emma) + 2000 + 6000 + 6400 + 400 = 16300
        // All-In底池: 9000(David) + 7000(Emma) = 16000
        // 每次分配: 16300 / 2 = 8150
        List<RunResult> runs = new ArrayList<>();
        int totalPot = 16300;
        int potSharePerRun = totalPot / 2;  // 8150
        
        // Run 1: Emma赢得一半底池（K对 > A高牌）
        List<PlayerRunDetail> run1Details = Arrays.asList(
            new PlayerRunDetail("player_david", "high_card", "A High", 0),
            new PlayerRunDetail("player_emma", "pair", "Pair of Kings", potSharePerRun)
        );
        runs.add(new RunResult(1, Arrays.asList("9d", "5d", "2h", "3c", "7s"), potSharePerRun, 
                               Arrays.asList("player_emma"), run1Details));
        
        // Run 2: David赢得另一半底池（方片同花 > K对）
        List<PlayerRunDetail> run2Details = Arrays.asList(
            new PlayerRunDetail("player_david", "flush", "Diamond Flush", potSharePerRun),
            new PlayerRunDetail("player_emma", "pair", "Pair of Kings", 0)
        );
        runs.add(new RunResult(2, Arrays.asList("9d", "5d", "2h", "Ad", "6d"), potSharePerRun, 
                               Arrays.asList("player_david"), run2Details));
        
        scenario.setRunItTwice(new RunItTwiceConfig(true, runs));
        
        // 最终赢家：Emma（净赢 +1150）
        scenario.setWinnerId("player_emma");
        
        return scenario;
    }
}

